home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / chap09 / howto03 / delphi10 / cciccinf.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-06-12  |  11.5 KB  |  346 lines

  1. unit Cciccinf;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, Grids, Outline, CCWSock;
  8.  
  9. type
  10.   TCCICInfoDlg = class(TForm)
  11.     Panel1: TPanel;
  12.     BitBtn1: TBitBtn;
  13.     BitBtn2: TBitBtn;
  14.     Panel4: TPanel;
  15.     ListBox2: TListBox;
  16.     Panel2: TPanel;
  17.     Edit1: TEdit;
  18.     Panel3: TPanel;
  19.     Edit2: TEdit;
  20.     Panel5: TPanel;
  21.     Edit3: TEdit;
  22.     Panel8: TPanel;
  23.     Edit4: TEdit;
  24.     Panel9: TPanel;
  25.     Edit5: TEdit;
  26.     Panel6: TPanel;
  27.     Outline1: TOutline;
  28.     Label1: TLabel;
  29.     Label2: TLabel;
  30.     Button1: TButton;
  31.     Button2: TButton;
  32.     Button3: TButton;
  33.     Button4: TButton;
  34.     procedure Button1Click(Sender: TObject);
  35.     procedure ListBox2Click(Sender: TObject);
  36.     procedure BitBtn1Click(Sender: TObject);
  37.     procedure BitBtn2Click(Sender: TObject);
  38.     procedure Edit4Exit(Sender: TObject);
  39.     procedure Button2Click(Sender: TObject);
  40.     procedure Button3Click(Sender: TObject);
  41.     procedure Button4Click(Sender: TObject);
  42.   private
  43.     { Private declarations }
  44.   public
  45.     { Public declarations }
  46.   end;
  47.  
  48. var
  49.   CCICInfoDlg: TCCICInfoDlg;
  50.  
  51. implementation
  52.  
  53. uses CCICCFrm;
  54.  
  55. function inet_addr( IPAddressName : PChar ) :
  56.           Unsigned_Long_Integer; far; external 'WINSOCK';
  57. function gethostbyname( TheName : PChar ) :
  58.           PHost_Entry; far; external 'WINSOCK';
  59. {$R *.DFM}
  60. procedure TCCICInfoDlg.Button1Click(Sender: TObject);
  61. var TempSocket : TCCSocket; { Used for IP Address info }
  62.     DataBuffer : array[ 0 .. 256 ] of char;
  63. begin
  64.   case Tag of
  65.     1 : begin  { Get IP Address Mode }
  66.           { Create the dummy socket }
  67.           TempSocket := TCCSocket.Create( Self );
  68.           TempSocket.Parent := Self;
  69.           { Use it to get the info }
  70.           with TempSocket do
  71.           begin
  72.             { Move the IP address into the data buffer }
  73.             StrPCopy( DataBuffer , Edit1.Text );
  74.             { Turn it into a real IP address in binary form }
  75.             Socket_IP_Address.Socket_Address.Full_Internet_Address :=
  76.              inet_addr( DataBuffer );
  77.             { If not found then do remote lookup }
  78.             if Socket_IP_Address.Socket_Address.Full_Internet_Address = INADDR_NONE then
  79.             begin
  80.               { Call blocking function on IP name }
  81.               Socket_Host_Entry := gethostbyname( DataBuffer );
  82.               { If still no good then error out and exit }
  83.               if Socket_Host_Entry = nil then
  84.               begin
  85.                 Edit2.Text := 'Could Not Convert Host Name';
  86.                 Edit3.Text := '';
  87.               end
  88.               else
  89.               begin
  90.                 { Otherwise get the address }
  91.                 Socket_IP_Address.Socket_Address :=
  92.                  Socket_Host_Entry^.Host_Address^^;
  93.                 Edit2.Text :=
  94.                  IntToStr( Socket_IP_Address.Socket_Address.Net_Byte ) + '.' +
  95.                  IntToStr( Socket_IP_Address.Socket_Address.Host_Byte ) + '.' +
  96.                  IntToStr( Socket_IP_Address.Socket_Address.Local_Host_Byte ) +
  97.                  '.' + IntToStr(
  98.                  Socket_IP_Address.Socket_Address.Local_Machine_Byte );
  99.                 Edit3.Text :=
  100.                  IntToStr( Socket_IP_Address.Socket_Address.
  101.                             Full_Internet_Address );
  102.               end;
  103.             end;
  104.           end;
  105.           { Free the dummy socket }
  106.           TempSocket.Free;
  107.         end;
  108.     2 : begin { Anonymous login punch }
  109.           Edit3.Text := 'anonymous';
  110.           CurrentRealPWString := CurrentPassWordString;
  111.           case PasswordControlVector of
  112.             1 : Edit4.Text := CurrentPassWordString;
  113.             2 : Edit4.Text := '**********';
  114.           end;
  115.         end;
  116.   end;
  117. end;
  118.  
  119. procedure TCCICInfoDlg.ListBox2Click(Sender: TObject);
  120. begin
  121.   { Use Tag vector to find out how to interpret a click }
  122.   case Tag of
  123.     2 : begin
  124.           { If nothing in list box then exit }
  125.           if ListBox2.ItemIndex = -1 then exit;
  126.           { Use the data in the Working FTP Site List TList }
  127.           with PConnectionsRecord(
  128.            TheWorkingFTPSL.Items[ ListBox2.ItemIndex ] )^ do
  129.           begin
  130.               Edit1.Text := CProfile;
  131.               Edit2.Text := CIPAddress;
  132.               Edit3.Text := CUserName;
  133.               CurrentRealPWString := CPassword;
  134.               case PasswordControlVector of
  135.                 1 : Edit4.Text := CPassword;
  136.                 2 : Edit4.Text := '**********';
  137.               end;
  138.               Edit5.Text := CStartDir;
  139.           end;
  140.         end;
  141.   end;
  142. end;
  143.  
  144. { This procedure saves the newly modified list of stuff to its base }
  145. procedure TCCICInfoDlg.BitBtn1Click(Sender: TObject);
  146. var Counter_1  : SmallInt;            { Loop counter        }
  147.     ThePointer : PConnectionsRecord; { Generic TCR Pointer }
  148. begin
  149.   { Use the tag vector to find out what to do }
  150.   case Tag of
  151.     2 : begin { Do FTP Site List }
  152.           { dispose the old FTP site list's pointers }
  153.           for Counter_1 := 0 to TheFTPSiteList.Count - 1 do
  154.           begin
  155.             Dispose( PConnectionsRecord( TheFTPSiteList.Items[ Counter_1 ] ));
  156.           end;
  157.           { Clear the lists }
  158.           TheFTPSiteList.Clear;
  159.           CCInetCCForm.ComboBox1.Clear;
  160.           { Add the new info }
  161.           for Counter_1 := 0 to TheWorkingFTPSL.Count - 1 do
  162.           begin
  163.             { Create a new pointer }
  164.             New( ThePointer );
  165.             { Move the data into it }
  166.             ThePointer^ :=
  167.              PConnectionsRecord( TheWorkingFTPSL.Items[ Counter_1 ] )^;
  168.             { Add the item }
  169.             TheFTPSiteList.Add( ThePointer );
  170.             CCINetCCForm.ComboBox1.Items.Add( PConnectionsRecord(
  171.              TheFTPSiteList.Items[ Counter_1 ] )^.CProfile );
  172.           end;
  173.           CCINetCCForm.ComboBox1.ItemIndex := 0;
  174.         end;
  175.   end;
  176.   { Leave }
  177.   Close;
  178. end;
  179.  
  180. { This method cancels any changes made from entries in current setup & exits}
  181. procedure TCCICInfoDlg.BitBtn2Click(Sender: TObject);
  182. var Counter_1  : SmallInt;            { Loop counter        }
  183.     ThePointer : PConnectionsRecord; { Generic TCR Pointer }
  184. begin
  185.   { Use Tag vector do decide what to reset }
  186.   case Tag of
  187.     2 : begin { Reset FTP Site list }
  188.           { Dispose of all the old pointers }
  189.           for Counter_1 := 0 to TheWorkingFTPSL.Count - 1 do
  190.           begin
  191.             Dispose( PConnectionsRecord( TheWorkingFTPSL.Items[ Counter_1 ] ));
  192.           end;
  193.           { Clear the working list }
  194.           TheWorkingFTPSL.Clear;
  195.           { Clear the listbox }
  196.           ListBox2.Clear;
  197.           { Then rebuild the working list and display listbox }
  198.           for Counter_1 := 0 to TheFTPSiteList.Count - 1 do
  199.           begin
  200.             { Create the record }
  201.             New( ThePointer );
  202.             { Move data in }
  203.             ThePointer^ :=
  204.              PConnectionsRecord( TheFTPSiteList.Items[ Counter_1 ] )^;
  205.             { Add the pointer to the list }
  206.             TheWorkingFTPSL.Add( ThePointer );
  207.             { Add the profile name to the list }
  208.             ListBox2.Items.Add( PConnectionsRecord(
  209.              TheFTPSiteList.Items[ Counter_1 ] )^.CProfile );
  210.           end;
  211.         end;
  212.   end;
  213.   { Leave }
  214.   Close;
  215. end;
  216.  
  217. procedure TCCICInfoDlg.Edit4Exit(Sender: TObject);
  218. begin
  219.   { Use tag vector to determine action }
  220.   case Tag of
  221.     2 : begin
  222.           { If Edit4 is modified then mangle pw }
  223.           if Edit4.Modified then
  224.           begin
  225.             { Save pw in either case, but mangle if masked }
  226.             case PasswordControlVector of
  227.               1 : CurrentRealPWString := Edit4.Text;
  228.               2 : begin
  229.                     CurrentRealPWString := Edit4.Text;
  230.                     Edit4.Text := '***********';
  231.                   end;
  232.             end;
  233.           end;
  234.         end;
  235.   end;
  236. end;
  237.  
  238. { Add button; do various add actions }
  239. procedure TCCICInfoDlg.Button2Click(Sender: TObject);
  240. var ThePointer : PConnectionsRecord; { PCR Pointer }
  241. begin
  242.   { Tag vector control as usual }
  243.   case Tag of
  244.     2 : begin { add new FTP site list entry }
  245.           { Creat new PCR pointer }
  246.           New( ThePointer );
  247.           { Add in the data from the text fields }
  248.           with ThePointer^ do
  249.           begin
  250.             CProfile   := Edit1.Text;
  251.             CIPAddress := Edit2.Text;;
  252.             CUserName  := Edit3.Text;
  253.             { Put in the real pw string }
  254.             CPassword  := CurrentRealPWString;
  255.             CStartDir  := Edit5.Text;
  256.           end;
  257.           { Add pointer to working list }
  258.           TheWorkingFTPSL.Add( ThePointer );
  259.           { Add it to the listbox }
  260.           ListBox2.Items.Add( ThePointer^.CProfile );
  261.           { And set the pointer to it }
  262.           ListBox2.ItemIndex := ListBox2.Items.Count - 1;
  263.         end;
  264.   end;
  265. end;
  266.  
  267. { This is the modify button }
  268. procedure TCCICInfoDlg.Button3Click(Sender: TObject);
  269. begin
  270.   { Use Tag vector as usual }
  271.   case Tag of
  272.     2 : begin
  273.           { if nothing to modify the exit }
  274.           if ListBox2.ItemIndex = -1 then exit;
  275.           { get record of current listbox pointer & put in data }
  276.           with PConnectionsRecord(
  277.            TheWorkingFTPSL.Items[ ListBox2.ItemIndex ] )^ do
  278.           begin
  279.             CProfile   := Edit1.Text;
  280.             CIPAddress := Edit2.Text;;
  281.             CUserName  := Edit3.Text;
  282.             { Put in the real pw string }
  283.             CPassword  := CurrentRealPWString;
  284.             CStartDir  := Edit5.Text;
  285.           end;
  286.           { Make sure the display matches the edit control }
  287.           ListBox2.Items[ ListBox2.ItemIndex ] := Edit1.Text;
  288.         end;
  289.   end;
  290. end;
  291.  
  292. { This is the delete button }
  293. procedure TCCICInfoDlg.Button4Click(Sender: TObject);
  294. var MessageString : string; { string holder }
  295. begin
  296.   { Use tag control vector }
  297.   case Tag of
  298.     2 : begin
  299.           { If nothing to delete then leave }
  300.           if Listbox2.Itemindex = -1 then exit;
  301.           { Set up display }
  302.           MessageString := 'Delete Entry ' + Edit1.Text + '?';
  303.           { Display message box and get result }
  304.           if MessageDlg( MessageString , mtConfirmation , mbYesNoCancel , 0 )
  305.            = mrYes then
  306.           begin
  307.             { if ok delete then remove item from working sl }
  308.             TheWorkingFTPSL.Delete( ListBox2.ItemIndex );
  309.             { delete from listbox }
  310.             ListBox2.Items.Delete( ListBox2.ItemIndex );
  311.             { If nothing left set itemindex and clear edits }
  312.             if ListBox2.Items.Count = 0 then
  313.             begin
  314.               ListBox2.ItemIndex := -1;
  315.               Edit1.Text := '';
  316.               Edit2.Text := '';
  317.               Edit3.Text := '';
  318.               Edit4.Text := '';
  319.               Edit5.Text := '';
  320.             end
  321.             else
  322.             begin
  323.               { Reset listbox pointer }
  324.               ListBox2.ItemIndex  := 0;
  325.               { and reset display to new item }
  326.               with PConnectionsRecord(
  327.                TheWorkingFTPSL.Items[ ListBox2.ItemIndex ] )^ do
  328.               begin
  329.                 Edit1.Text := CProfile;
  330.                 Edit2.Text := CIPAddress;
  331.                 Edit3.Text := CUserName;
  332.                 CurrentRealPWString := CPassword;
  333.                 case PasswordControlVector of
  334.                   1 : Edit4.Text := CPassword;
  335.                   2 : Edit4.Text := '**********';
  336.                 end;
  337.                 Edit5.Text := CStartDir;
  338.               end;
  339.             end;
  340.           end;
  341.         end;
  342.   end;
  343. end;
  344.  
  345. end.
  346.